package com.verisette.ncos.service.accesscontrol.bizunit;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bean.UserBean;
import org.corp.agi.service.bizunit.CommonBusinessUnit;
import com.verisette.ncos.common.ProjectConstant;
import com.verisette.ncos.persistence.domain.LogUserAccess;
import com.verisette.ncos.persistence.domain.MasterUserProfile;

/**
 * {Description here}
 *
 * @author Thippawan Muangchu (Tip)
 * @since Oct 5, 2010 2:11:32 PM
 * @version 1.0.0
 * @see 
 */
@Transactional(propagation=Propagation.REQUIRES_NEW)
public class InsertAccessLogBU  extends CommonBusinessUnit {
	
	private Logger logger = Logger.getLogger(InsertAccessLogBU.class);

	@Override
	public void execute(ProcessContext processContext) throws ProcessException {

		Map<String, Object> inputMap = (Map<String, Object>)processContext.getValueObject();
		
		String logMessage = (String)inputMap.get(ProjectConstant.ACCESS_LOG_MESSAGE);
		String ipAddress = (String)inputMap.get(ProjectConstant.USER_PROFILE_IP_ADDRESS);
		MasterUserProfile authenUser = (MasterUserProfile) inputMap.get(ProjectConstant.USER_PROFILE);
		
		LogUserAccess logUserAccess = new LogUserAccess();
		logUserAccess.setUspId(authenUser.getUspId());
		logUserAccess.setActionDescription(logMessage);
		logUserAccess.setUacDatetime(new Timestamp(new Date().getTime()));
		logUserAccess.setUacIpAddr(ipAddress);
		commonDAO.save(logUserAccess);
		
	}

}
